﻿using Microsoft.Owin.Hosting;
using NLog;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;

namespace Goooodbye.Presentation.WebApi
{
    internal class Program
    {
        private static readonly Logger logger = LogManager.GetLogger(Assembly.GetExecutingAssembly().GetName().Name);
        static void Main(string[] args)
        {
            try
            {
                var processes = Process.GetProcessesByName(Application.ProductName);
                if (processes.Length <= 1)
                {
                    var url = $"http://localhost:31415";
                    using (WebApp.Start(url))
                    {
                        logger.Info($"Server running at {url}");
                        Application.Run();
                    }
                }
                else
                {
                    MessageBox.Show(Application.ProductName + " 已经在运行中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex.InnerException ?? ex);
                Console.WriteLine("按任意键退出");
                Console.ReadKey(true);
            }
        }
    }
}
